package com.caocaog.market.controller;

import com.caocaog.market.entity.GoodsAttr;
import com.caocaog.market.service.GoodsAttrService;
import com.caocaog.market.vo.GoodsAttributeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.GenericController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * 商品属性
 *
 * @author chechen
 * @date 2022-04-18
 */
@RestController
@Api(value = "goodsAttr", tags = "商品属性")
@RequestMapping("/goods/goodsAttribute")
public class GoodsAttrController extends GenericController<GoodsAttr, GoodsAttrService> {

    /**
     * 通过商品id查询商品属性信息vo
     *
     * @param goodsId 商品id
     * @return 商品属性vo
     */
    @ApiOperation(value = "商品信息-通过id查询获取商品属性", notes = "商品信息-通过id查询获取商品属性")
    @GetMapping(value = "/getGoodsAttributeDataByGoodsId/{goodsId}")
    public Result<List<GoodsAttributeVo>> getGoodsAttributeDataByGoodsId(@PathVariable String goodsId) {
        List<GoodsAttributeVo> goodsAttributeVoList = super.service.getGoodsAttrVOByGoodsId(goodsId);
        if (goodsAttributeVoList.isEmpty())
            return Result.OK("该商品暂无属性", Collections.emptyList());
        return Result.OK(goodsAttributeVoList);
    }

}
